<?php
namespace Rainrock\Framework\Controller;



use Rainrock\Framework\kernel\core\Module;
use Rainrock\Framework\kernel\base\Request;
use Rainrock\Framework\kernel\base\Auth;
use Rainrock\Framework\kernel\base\Jiami;
use Rainrock\Framework\kernel\Html\HtmlBase;
use Rainrock\Framework\kernel\Html\HtmlLabel;
use Rainrock\Framework\kernel\Html\HtmlImage;
use Rainrock\Framework\kernel\Html\HtmlButton;

/**
*	个人
*/
class GerenController extends AuthController{
	
	
	
	public function indexAction()
	{
		$html = new HtmlBase();
		$html->setTitle('个人中心');
		$html->addJse('login');
		$html->addCont($this->viewShow());
		return $html->show();
	}
	
	
	public function viewShow($lx=0)
	{
		$mdiv = HtmlLabel::get();
		
		$mdiv->addCont(HtmlLabel::get()->setAlign('center')->setMargin(20,'top')->addCont(HtmlImage::gets()->setSrc(Auth::getUserInfo('face'))->setId('myface')->setWidth(100)->setHeight(100,'hidden')->setRadius('50%')->setonClick('js.viewimg(this)')));
		
		$border		= 'var(--border)';
		
		$mdivs = HtmlLabel::get()->setAlign('left')
				->setWidth('280px')
				->addCss('mainbody')
				->addStyle('border',$border)
				->setRadius(10)
				->setMargin(15);
		
		
		$mdivs->addCont(
			HtmlLabel::get()->setDisplay('flex')->addStyle('border-bottom',$border)->setPadding(15)
			->addCont(HtmlLabel::get()->addCont('姓名'))
			->addCont(
				HtmlLabel::get()->setAlign('right')->addStyle('flex',1)->addCont(Auth::$NAME)
				//->addKong()
				//->addCont(HtmlLabel::get('span')->addCss('hui')->addCont('&gt;'))
			)
		);
		
		$mdivs->addCont(
			HtmlLabel::get()->setDisplay('flex')->addStyle('border-bottom',$border)->setPadding(15)
			->addCont(HtmlLabel::get()->addCont('帐号'))
			->addCont(HtmlLabel::get()->setAlign('right')->addStyle('flex',1)->addCont(Auth::getUserInfo('user')))
		);
		
		$mobile = Jiami::base64decode(Auth::getUserInfo('mobile'));
		if(!$this->isempt($mobile))$mobile = substr($mobile,0,3).'****'.substr($mobile,-4);
		$mdivs->addCont(
			HtmlLabel::get()->setDisplay('flex')->addStyle('border-bottom',$border)->setPadding(15)
			->addCont(HtmlLabel::get()->addCont('手机号'))
			->addCont(HtmlLabel::get()->setAlign('right')->addStyle('flex',1)->addCont($mobile))
		);
		
		$mdivs->addCont(
			HtmlLabel::get()->setDisplay('flex')->addStyle('border-bottom',$border)->setPadding(15)
			->addCont(HtmlLabel::get()->addCont('职位'))
			->addCont(HtmlLabel::get()->setAlign('right')->addStyle('flex',1)->addCont(Auth::getUserInfo('ranking')))
		);
		
		$mdivs->addCont(
			HtmlLabel::get()->setDisplay('flex')->setValign()->addStyle('border-bottom',$border)->setPadding(15)
			->addCont(HtmlLabel::get()->addCont('添加时间'))
			->addCont(HtmlLabel::get()->setAlign('right')->setFontsize(12)->addStyle('flex',1)->addCont(Auth::getUserInfo('adddt')))
		);
		
		$mdivs->addCont(
			HtmlLabel::get()->setDisplay('flex')->setonClick('ind.editface()')->addCss('hover')->addStyle('border-bottom',$border)->setPadding(15)
			->addCont(HtmlLabel::get()->addCont('修改头像'))
			->addCont(HtmlLabel::get()->setAlign('right')->addCss('hui')->addStyle('flex',1)->addCont('&gt;'))
		);
		
		$mdivs->addCont(
			HtmlLabel::get()->setDisplay('flex')->addCss('hover')->setPadding(15)
			->addCont(HtmlLabel::get()->addCont('修改密码'))
			->addCont(HtmlLabel::get()->setAlign('right')->addCss('hui')->addStyle('flex',1)->addCont('&gt;'))
		);
		
		
				
		
		$mdiv->addBody($mdivs);
		
		$btn = HtmlButton::gets()
			->addStyle('text-align','center')
			->setWidth('120px')
			->addCss('webbtn')
			->setonClick('loginexit()')
			->setBackgroundColor('#D9534F')
			->addCont('退出');
		
		if($lx==0){
			$mdiv->addBody(
				HtmlLabel::get()
				->addCont(HtmlLabel::get('a')->addCont('&lt;返回')->setFontsize(14)->setHref('javascript:js.back()'))
				->addKong()
				->addKong()
				->addKong()
				->addCont($btn)
			);
		}else{
			$mdiv->addBody(
				HtmlLabel::get()->addCont($btn)
			);
		}
		
		return $mdiv;
	}
	
	
	public function viewAction()
	{
		$mdiv = $this->viewShow(1);
		return $mdiv->show();
	}
	
	/**
	*	保存
	*/
	public function saveAction()
	{
		$farr 	= array('face','name','ranking');
		$fields = Request::get('fields');
		$value 	= Request::get('value');
		if(!$fields || !in_array($fields, $farr))return $this->returnerror('error');
		$this->m('systoken')->saveInfo(Auth::$USERID, $fields, Jiami::base64decode($value));
		if($this->dbError(true))return $this->returnerror($this->dbError());
		return $this->returnsuccess();
	}
}